/* Copyright 2008 Milko Slavov
 * This file is part of GEH.
 * GEH is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * GEH is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * See <http://www.gnu.org/licenses/>.
*/
package com.geh.event.example;

import com.geh.event.EventHandler;

public class ValueHolder
{
   private EventHandler<ValueEvent, ValueListener> handler = new EventHandler<ValueEvent, ValueListener>(
                                                                    new String[] {                                                                             
                                                                             "onCreate", 
                                                                             "onUpdate", 
                                                                             "onRemove"                     
                                                                             });
   private Object value;

   
   public void addValueListener(ValueListener listener)
            throws IllegalArgumentException
   {
      handler.addListener(listener);
   }

   public void removeValueListener(ValueListener listener)
   {
      handler.removeListener(listener);
   }

   public void createValue(Object value)
   {
      ValueEvent event = new ValueEvent(this.value, value, this);
      this.value = value;
      handler.fireEvent("onCreate", event);
   }

   public void updateValue(Object value)
   {
      ValueEvent event = new ValueEvent(this.value, value, this);
      this.value = value;
      handler.fireEvent("onUpdate", event);
   }

   public void removeValue()
   {
      ValueEvent event = new ValueEvent(this.value, null, this);
      this.value = null;
      handler.fireEvent("onRemove", event);
      handler.dispose();
   }
}
